package com.app.oasystem.controller;


import com.app.oasystem.dto.ActionResult;
import com.app.oasystem.dto.MailDto;
import com.app.oasystem.entity.Email;
import com.app.oasystem.entity.User;
import com.app.oasystem.mapper.UserMapper;
import com.app.oasystem.service.impl.EmailServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 86+
 * @data 2021-04-13
 */

@RestController
@RequestMapping("/email")
public class EmailController {

    @Resource
    EmailServiceImpl emailService;

    @Resource
    UserMapper userMapper;

    /**
     * 获取用户信息
     */
    @PostMapping("/send")
    public ActionResult sendMail(@RequestBody MailDto mailDto) {
        return (ActionResult)emailService.sendMail(mailDto);
    }

    /**
     * 根据情况获取邮箱信息
     */
    @GetMapping("/book/{mailId}/{id}")
    public ActionResult getInboxEmailList(@PathVariable("mailId") Integer mailId,@PathVariable("id")Integer id) {
        List<Email> emailList = emailService.getEmailList(mailId,id);

        return new ActionResult(emailList);
    }

    /**
     * 根据id获取邮件信息
     */
    @GetMapping("/{mailId}")
    public ActionResult getEmailInfoById(@PathVariable("mailId") Integer mailId) {
        return new ActionResult(emailService.getEmailInfoById(mailId));
    }

    @DeleteMapping("/{mailId}")
    public ActionResult deleteEmailById(@PathVariable("mailId") Integer mailId) {
        return new ActionResult(emailService.deleteEmailById(mailId));
    }

    @DeleteMapping("/del/{mailId}")
    public ActionResult deleteEmail(@PathVariable("mailId") Integer mailId) {
        return new ActionResult(emailService.deleteEmail(mailId));
    }

    @PutMapping("/{mailId}")
    public void updateEmailStatus(@PathVariable("mailId") Integer mailId) {
        emailService.updateEmailStatus(mailId);
    }

    @PutMapping("reset/{mailId}")
    public ActionResult resetEmailStatus(@PathVariable("mailId") Integer mailId) {
        return new ActionResult(emailService.resetEmailStatus(mailId));
    }

}

